<?php
/**
 * Created by PhpStorm.
 * User: hedonglin
 * Date: 2017/10/31
 * Time: 9:40
 */

namespace app\admin\controller;


use think\Controller;
use think\Db;

class Erecordnew extends Controller
{
    /**
     * 评教结果视图
     * @return mixed
     */
    public function index() {

        return $this->fetch();
    }

    /**
     * 分页查询查询结果
     * @param int $pageNumber
     * @param int $pageSize
     * @param string $searchText
     * @return \think\response\Json
     */
    public function getList($pageNumber = 1, $pageSize = 5, $searchText = '%'){
        $result = DB::table("oes_erecordnew")->alias("result")
            ->join("oes_etask task","task.id = result.etask_id","LEFT")
            ->join("oes_etype type","type.id = result.etype_id","LEFT")
            ->join('oes_user u',"u.id = result.euser_id","LEFT")
            ->join("oes_emp emp","emp.id = result.teacher_id","LEFT")
            ->join("oes_clazz clazz","clazz.id = result.clazz_id","LEFT")
            ->join("oes_course course","course.id = result.course_id","LEFT")
            ->field("result.*,
                    task.`name` etask_name,
                    type.`name` etype_name,
                    u.username euser_name,
                    emp.`name` teacher_name,
                    clazz.`name` clazz_name,
                    course.`name` course_name")
            ->where("
            task.`name` LIKE :etask_name or
            type.`name` LIKE :etype_name or
            u.`username` LIKE :euser_name or
            emp.`name` LIKE :teacher_name or
            clazz.`name` LIKE :clazz_name or
            course.`name` LIKE :course_name
            "
            ,[
                'etask_name'=>'%'.$searchText.'%',
                'etype_name'=>'%'.$searchText.'%',
                'euser_name'=>'%'.$searchText.'%',
                'teacher_name'=>'%'.$searchText.'%',
                'clazz_name'=>'%'.$searchText.'%',
                'course_name'=>'%'.$searchText.'%'
            ])
            ->paginate($pageSize, false, ["page"=>$pageNumber]);

            return json($result);
    }




}